package com.srzk.youthleagueback.mapper;

import com.srzk.youthleagueback.pojo.Meeting;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

public class MeetingProvider extends SQL {
    private static final String TABLE_NAME = "meeting";

    public String updateMeeting(@Param("meeting") Meeting meeting) {
        return new SQL() {{
            UPDATE(TABLE_NAME);
            if (!StringUtils.isEmpty(meeting.getUser())) {
                SET("user = #{user}");
            }
            if (!StringUtils.isEmpty(meeting.getYear())) {
                SET("year= #{year}");
            }
            if (!StringUtils.isEmpty(meeting.getType().toString())) {
                SET("type= #{type}");
            }
            if (!StringUtils.isEmpty(meeting.getId().toString())) {
                SET("id= #{id}");
            }
            if (!ObjectUtils.isEmpty(meeting.getDate())) {
                SET("date= #{date}");
                SET("address= #{address}");
                SET("host= #{host}");
                SET("subject= #{subject}");
                SET("content= #{content}");
                SET("`condition`= #{condition}");
                SET("summary= #{summary}");
                SET("count= #{count}");
            }
            WHERE("id = #{id}");
            WHERE("user = #{user}");
            WHERE("year= #{year}");
            WHERE("type= #{type}");
        }}.toString();
    }
}
